package jt.classic.system.objectquery.impl;

import jt.classic.system.objectquery.ObjectQueryItem;
import jt.classic.system.wordbook.XWordbook;
import jt.classic.system.wordbook.XWordbookMain;
import jt.classic.system.wordbook.XWordbookQuery;

import org.limp.basework.AbstractSimpleBean;
import org.limp.basework.Column;

import org.limp.mine.StringTool;

import java.util.Map;


/**
 * 查询项接口实行类
 *
 * @author mido
 *
 */
public class ObjectQueryItemImpl extends AbstractSimpleBean
    implements ObjectQueryItem {
    private String fieldName;
    private String clazz;
    private String label;
    private String param;
    private String mode;
    private Column column;
    private String type;
    private boolean alien;
    private String need;
    private String pointId;
    private String pointName;
    private String show;

    public String ifieldName() {
        return this.fieldName;
    }

    public String iclass() {
        // TODO Auto-generated method stub
        return this.clazz;
    }

    public boolean ialien() {
        return this.alien;
    }

    public String imode() {
        // TODO Auto-generated method stub
        return this.mode;
    }

    public Column icolumn() {
        // TODO Auto-generated method stub
        return this.column;
    }

    public String itype() {
        // TODO Auto-generated method stub
        return this.type;
    }

    public String iparam() {
        return this.param;
    }

    public String ilabel() {
        return this.label;
    }

    public String translate(String value) {
        String transValue = null;

        String param = StringTool.checkString(this.param);

        if (!param.equals("") && (param.indexOf(";") == -1)) {
            XWordbookMain wbmain = XWordbookMain.getInstance();
            XWordbookQuery wbquery = wbmain.getWordbookQuery(param);

            if (wbquery != null) {
                XWordbook wb = wbquery.query(value);

                if (wb != null) {
                    transValue = wb.getName();
                } else {
                    transValue = value;
                }
            } else {
                transValue = value;
            }
        } else if (!param.equals("") && (param.indexOf(";") > -1)) {
            String[] strs = param.split(";");

            for (int i = 0; i < strs.length; i++) {
                if (!strs[i].equals("") && (strs[i].indexOf(":") > -1) &&
                        strs[i].substring(0, strs[i].indexOf(":")).equals(value)) {
                    transValue = strs[i].substring(strs[i].indexOf(":") + 1);

                    if (transValue.equals("")) {
                        transValue = value;

                        break;
                    }
                }
            }
        } else {
            transValue = value;
        }

        return transValue;
    }

    public String ineed() {
        return this.need;
    }

    public String ipointId() {
        return this.pointId;
    }

    public String ipointName() {
        return this.pointName;
    }

    public void reload(Map temp) {
        if (temp != null) {
            this.info = temp;
        }

        this.fieldName = (String) this.info.get("fieldName");
        this.clazz = (String) this.info.get("class");
        this.alien = "1".equals((String) this.info.get("alien"));
        this.mode = (String) this.info.get("mode");
        this.column = (Column) this.info.get("column");
        this.type = (String) this.info.get("type");
        this.label = (String) this.info.get("label");
        this.param = (String) this.info.get("param");
        this.pointId = (String) this.info.get("pointId");
        this.pointName = (String) this.info.get("pointName");
        this.need = (String) this.info.get("need");
        this.show = (String) this.info.get("show");
    }

    public String ishow() {
        return show;
    }
}
